package handlers

import (
	"github.com/gin-gonic/gin"
	"order-master1/models"
)

/*
SELECT
*
FROM
roles
LEFT JOIN
user_roles
ON
user_roles.rid=roles.id
WHERE
user_roles.uid=1
*/

func FindUserRole(c *gin.Context) {
	id := c.Query("id")

	var role models.Role
	models.DB.Table("roles").
		Select("*").
		Joins("LEFT JOIN user_roles ON user_roles.rid = roles.id").
		Where("user_roles.uid=?", id).
		Find(&role)

	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "success",
		"data": role,
	})
	return
}
